package com.app.ui.activity.account;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.EditText;

import com.app.net.res.user.User;
import com.app.ui.activity.action.NormalActionBar;
import com.app.utiles.other.ToastUtile;
import com.wxj.zx.R;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.bmob.v3.listener.UpdateListener;


/**修改密码
 * Created by Administrator on 2016/2/15.
 */
public class UserPasswordActivity extends NormalActionBar {


    @Bind(R.id.user_password_et)
    EditText userPasswordEt;
    @Bind(R.id.user_new_password_et)
    EditText userNewPasswordEt;
    @Bind(R.id.user_new_password2_et)
    EditText userNewPassword2Et;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_password);
        setBarColor();
        ButterKnife.bind(this);
        setBarBack();
        setBarTvText(1, "修改密码");
        setBarTvText(2, "修改");
    }

    @Override
    protected void option() {
        String passwoedOld = userPasswordEt.getText().toString();
        String password = userNewPasswordEt.getText().toString();
        String password2 = userNewPassword2Et.getText().toString();
        if (TextUtils.isEmpty(passwoedOld) || passwoedOld.length() < 6) {
            ToastUtile.showToast("请输入6-20位旧密码");
            return;
        }
        if (TextUtils.isEmpty(password) || password.length() < 6) {
            ToastUtile.showToast("请输入6-20位密码");
            return;
        }
        if (!password.equals(password2)) {
            ToastUtile.showToast("2次输入的新密码不一致");
            return;
        }
        User user = baseApplication.getUser();
        dialogShow();
        user.updateCurrentUserPassword(this, passwoedOld, password, new UpdatePasswordListener());
    }

    //修改密码监听
    class UpdatePasswordListener extends UpdateListener {

        @Override
        public void onSuccess() {
            dialogDismiss();
            ToastUtile.showToast("修改成功");
            finish();
        }

        @Override
        public void onFailure(int i, String s) {
            dialogDismiss();
            ToastUtile.showToast("修改失败");
        }
    }

}
